#include <iostream>
#include <windows.h>
#include <conio.h>

void clearScreen() {
	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	if (hConsole == INVALID_HANDLE_VALUE) {
		std::cerr << "Failed to get console handle." << std::endl;
		return;
	}
	COORD coordScreen = { 0, 0 };
	DWORD cCharsWritten;
	CONSOLE_SCREEN_BUFFER_INFO csbi;
	if (!GetConsoleScreenBufferInfo(hConsole, &csbi)) {
		std::cerr << "Failed to get console screen buffer info." << std::endl;
		return;
	}
	DWORD dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
	// 填充空格
	if (!FillConsoleOutputCharacter(hConsole, (TCHAR)' ', dwConSize, coordScreen, &cCharsWritten)) {
		std::cerr << "Failed to fill console buffer." << std::endl;
		return;
	}
	// 将光标设置到左上角
	if (!SetConsoleCursorPosition(hConsole, coordScreen)) {
		std::cerr << "Failed to set cursor position." << std::endl;
		return;
	}
}

int main() {
	// 获取标准输出句柄
	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	if (hConsole == INVALID_HANDLE_VALUE) {
		std::cerr << "Failed to get console handle." << std::endl;
		return 1;
	}
	
	// 获取当前控制台字体信息
	CONSOLE_FONT_INFOEX cfi;
	cfi.cbSize = sizeof(cfi);
	if (!GetCurrentConsoleFontEx(hConsole, FALSE, &cfi)) {
		std::cerr << "Failed to get current console font information." << std::endl;
		return 1;
	}
	
	// 修改字体信息
	cfi.dwFontSize.X = 10;  // 设置字体宽度
	cfi.dwFontSize.Y = 20;  // 设置字体高度
	wcscpy_s(cfi.FaceName, L"Consolas");  // 设置字体名称
	
	// 设置新的控制台字体信息
	if (!SetCurrentConsoleFontEx(hConsole, FALSE, &cfi)) {
		std::cerr << "Failed to set console font." << std::endl;
		return 1;
	}
	
	std::cout << "Console font has been changed." << std::endl;
	
	std::cout << "\u250c\u2500\u2510" << std::endl;
	std::cout << "\u2502a\u2502" << std::endl;
	std::cout << "\u2514\u2500\u2518" << std::endl;
	
	CONSOLE_SCREEN_BUFFER_INFO csbi;
	if (!GetConsoleScreenBufferInfo(hConsole, &csbi)) {
		std::cerr << "Failed to get console screen buffer info." << std::endl;
		return 1;
	}
	
	int consoleWidth = csbi.dwSize.X;  // 控制台缓冲区的宽度（字符数）
	int consoleHeight = csbi.dwSize.Y; // 控制台缓冲区的高度（字符数）
	
	std::cout << "Console Width (in characters): " << consoleWidth << std::endl;
	std::cout << "Console Height (in characters): " << consoleHeight << std::endl;
	
	//clearScreen();
	
	kbhit();
	return 0;
}
